<?php
/**
 * 显示收藏夹数据
 */

//连接到数据库
include './config/config.inc.php';
include './include/db.php';


$query_count = "select count(*) as amount from favourite WHERE uid=$XJH_uid";
$query_data = 'SELECT `favourite`.`Id`, `Title`, `HoldTime`, `Address`, `IssueTime`, `Url`
  FROM `favourite`, `xjhinfo`
  WHERE `favourite`.`uid` = '.$XJH_uid.'
  AND `favourite`.`InfoID` = `xjhinfo`.`InfoID`
  AND `xjhinfo`.`Disabled` = 0';
$result = mysql_query($query_count);
if (!$result) {
    die('Error: ' . mysql_error());
}
$row = mysql_fetch_array($result);
$row['amount'] = ceil(($row['amount']) / $count);
$rows[] = $row;

$result = mysql_query($query_data);
if (!$result) {
    die('Error: ' . mysql_error());
}

echo '<table>
    <tr>
        <th>宣讲标题 </th>
        <th>举办时间</th>
        <th>举办地点</th>
        <th>发布时间</th>
        <th></th>
    </tr>';
    while ($info = mysql_fetch_array($result)) 
    {
        //print_r($info);
        echo '
        <tr class="con_tb_row" id="row-'.$info['Id'].'">
        	<td class="con_tb_normal">
                <a href="'.$info["Url"].'">
                	<strong>'.$info["Title"].'</strong>
                </a>
            </td>
            <td class="con_tb_normal">'.$info["HoldTime"].'</td>
            <td class="con_tb_normal">'.$info["Address"].'</td>
            <td class="con_tb_normal">'.$info["IssueTime"].'</td>
            <td class="con_tb_normal">
            	<a href="#" class="RemoveLink" onclick="remove('.$info["Id"].')">删除</a>
            </td>
        </tr>';
    }
  
echo '</table>';
?>

<script type="text/javascript">
    function remove(recordToDelete) {
       if (recordToDelete != 0) {
        	$.post("./lib/data/favourite_delete.php", { "id": recordToDelete },
            	function (data) {
                	if (data != 0) {
                    	$('#row-' + data).fadeOut('slow');
                	} 
            });
    	}
    }

</script>
